package org.dcma.client.centros;

import java.util.List;

import org.dcma.model.Centro;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class CentroServiceDelegate {
	private CentroServiceAsync centroService=GWT.create(CentroService.class);
	CentrosGui centrosGui;
	
	void listCentros() {
        centroService.listCentros(new AsyncCallback<List<Centro>>() {			
			public void onFailure(Throwable caught) {
				centrosGui.show_message(caught.getLocalizedMessage());				
			}

			public void onSuccess(List<Centro> result) {
				/*centrosGui.show_message("cargando centros");
				 * 
				 */
				if (result.equals(null)){
					centrosGui.list_centros(result);
				}else {
					centrosGui.show_message("no hay centros registrados");
				}
			}
		});
    }
	
	void addCentro(final Centro centro) {
        centroService.addCentro(centro, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
            	centrosGui.show_message(caught.getLocalizedMessage());
            }

            public void onSuccess(Void result) {
            	centrosGui.show_message("Centro agregado con exito");
            }
        }//end of inner class
        );//end of addDepartamento method call.        
    }
}
